#include "stdafx.h"
#include "CppUnitTest.h"
#include "FileNameTokenizer.h"

#include <string>

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;

namespace UnitTests
{
   TEST_CLASS(DicomAttributeTests)
   {
   public:
      TEST_METHOD(FileNameTokenizerCanHandleNarrowStandardPath)
      {
         // given
         string path{ "C:\\Narrow\\Standard\\Path\\To\\File.ext" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\To\\", sut.Directory.c_str());
         Assert::AreEqual("File", sut.Name.c_str());
         Assert::AreEqual(".ext", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\To\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"File", sut.NameW.c_str());
         Assert::AreEqual(L".ext", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleWideStandardPath)
      {
         // given
         wstring path{ L"C:\\Narrow\\Standard\\Path\\To\\File.ext" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\To\\", sut.Directory.c_str());
         Assert::AreEqual("File", sut.Name.c_str());
         Assert::AreEqual(".ext", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\To\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"File", sut.NameW.c_str());
         Assert::AreEqual(L".ext", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleNarrowRootPath)
      {
         // given
         string path{ "C:\\File.ext" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\", sut.Directory.c_str());
         Assert::AreEqual("File", sut.Name.c_str());
         Assert::AreEqual(".ext", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"File", sut.NameW.c_str());
         Assert::AreEqual(L".ext", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleWideRootPath)
      {
         // given
         wstring path{ L"C:\\File.ext" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\", sut.Directory.c_str());
         Assert::AreEqual("File", sut.Name.c_str());
         Assert::AreEqual(".ext", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"File", sut.NameW.c_str());
         Assert::AreEqual(L".ext", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleNarrowPathNoFile)
      {
         // given
         string path{ "C:\\Narrow\\Standard\\Path\\To\\NoFile\\" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\To\\NoFile\\", sut.Directory.c_str());
         Assert::AreEqual("", sut.Name.c_str());
         Assert::AreEqual("", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\To\\NoFile\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"", sut.NameW.c_str());
         Assert::AreEqual(L"", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleWidePathNoFile)
      {
         // given
         wstring path{ L"C:\\Narrow\\Standard\\Path\\To\\NoFile\\" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\To\\NoFile\\", sut.Directory.c_str());
         Assert::AreEqual("", sut.Name.c_str());
         Assert::AreEqual("", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\To\\NoFile\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"", sut.NameW.c_str());
         Assert::AreEqual(L"", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleNarrowPathNoExt)
      {
         // given
         string path{ "C:\\Narrow\\Standard\\Path\\To\\NoExt" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\To\\", sut.Directory.c_str());
         Assert::AreEqual("NoExt", sut.Name.c_str());
         Assert::AreEqual("", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\To\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"NoExt", sut.NameW.c_str());
         Assert::AreEqual(L"", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleWidePathNoExt)
      {
         // given
         wstring path{ L"C:\\Narrow\\Standard\\Path\\To\\NoExt" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("C:", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\To\\", sut.Directory.c_str());
         Assert::AreEqual("NoExt", sut.Name.c_str());
         Assert::AreEqual("", sut.Extension.c_str());
         Assert::AreEqual(L"C:", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\To\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"NoExt", sut.NameW.c_str());
         Assert::AreEqual(L"", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleNarrowPathNoDrive)
      {
         // given
         string path{ "\\Narrow\\Standard\\Path\\No\\Drive\\File.ext" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\No\\Drive\\", sut.Directory.c_str());
         Assert::AreEqual("File", sut.Name.c_str());
         Assert::AreEqual(".ext", sut.Extension.c_str());
         Assert::AreEqual(L"", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\No\\Drive\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"File", sut.NameW.c_str());
         Assert::AreEqual(L".ext", sut.ExtensionW.c_str());
      }

      TEST_METHOD(FileNameTokenizerCanHandleWidePathNoDrive)
      {
         // given
         wstring path{ L"\\Narrow\\Standard\\Path\\No\\Drive\\File.ext" };

         // when
         FileNameTokenizer sut{ path };

         // then
         Assert::AreEqual("", sut.Drive.c_str());
         Assert::AreEqual("\\Narrow\\Standard\\Path\\No\\Drive\\", sut.Directory.c_str());
         Assert::AreEqual("File", sut.Name.c_str());
         Assert::AreEqual(".ext", sut.Extension.c_str());
         Assert::AreEqual(L"", sut.DriveW.c_str());
         Assert::AreEqual(L"\\Narrow\\Standard\\Path\\No\\Drive\\", sut.DirectoryW.c_str());
         Assert::AreEqual(L"File", sut.NameW.c_str());
         Assert::AreEqual(L".ext", sut.ExtensionW.c_str());
      }
   };
}